//
// ***********************************************
// *    ___________   ___________  __      __    *
// *   |______  __/  /_____  ___/  \ \    / /    *
// *         / /          / /       \ \  / /     *
// *        / /          / /         \ \/ /      *
// *       / /          / /           \  /       *
// *      / /______    / /            / /        *
// *     /________/   /_/            /_/         *
// *                                             *
// ***********************************************
//
//   SelViewController.m
//   welfareMallDemo
//   
//   Created  by mac on 2019/9/27
//   Modified by Tiyon
//   Copyright © 2019 wanmeizty. All rights reserved.
//   
   

#import "SelViewController.h"
#define ztyRGBHexAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
@interface SelViewController ()
@property (assign,nonatomic) BOOL isrelease;
@property (strong,nonatomic) UITextField * uidText;
@end

@implementation SelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"首页";
    _isrelease = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.uidText = [[UITextField alloc] initWithFrame:CGRectMake(40, 100, self.view.frame.size.width - 80, 40)];
    self.uidText.placeholder = @"请输入uid";
    self.uidText.text = @"1020045";
    [self.view addSubview:self.uidText];
    
    NSArray * titles = @[@"高佣",@"淘头条"];
    for (int i = 0; i < titles.count; i ++) {
        UIButton *  btn = [[UIButton alloc] initWithFrame:CGRectMake(40, 160 + 60 * i, self.view.frame.size.width - 80, 40)];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        NSString * title = titles[i];
        btn.tag = 200 + i;
        [btn setTitle:title forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(goIntoPage:) forControlEvents:UIControlEventTouchUpInside];
        btn.backgroundColor = ztyRGBHexAlpha(0xFF7200, 1);
        btn.layer.cornerRadius = 20;
        btn.layer.masksToBounds = YES;
        [self.view addSubview:btn];
    }
    
    
    UIButton *  btn = [[UIButton alloc] initWithFrame:CGRectMake(40, 160 + 60 * titles.count + 50 , self.view.frame.size.width - 80, 40)];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"勾选正式环境" forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"con_nor"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"con_sel"] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(selectrelease:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.uidText resignFirstResponder];
}

-(void)selectrelease:(UIButton *)sender{
    sender.selected = !sender.selected;
    self.isrelease = sender.selected;
}

-(void)goIntoPage:(UIButton *)btn{
    
    NSDictionary * dict = [[NSMutableDictionary alloc] init];
    
    [dict setValue:@(self.isrelease) forKey:@"isrelease"];
    
    
    [dict setValue:self.uidText.text forKey:@"uid"];
    
    if (btn.tag == 200) {
        NSString * clientId = @"81c1b54196a046a78a4f78f917a8b469";   //兜推-平台申请的clientId
        NSString * clientSecret = @"1764a15d67714016abb08091bc866ba8f588bb76";  //兜推-平台申请的clientSecret
       
        [dict setValue:clientId forKey:@"clientId"];
        [dict setValue:clientSecret forKey:@"clientSecret"];
    }else if (btn.tag == 201){
        
        NSString * clientId = @"f6d953b1045b42dbb21feb7a26a7ffd1";   //驾校-平台申请的clientId
        NSString * clientSecret = @"f4bd85c4d7264f12a8a1b4a265ed4d8e10421ee2";  //驾校-平台申请的clientSecret
        [dict setValue:clientId forKey:@"clientId"];
        [dict setValue:clientSecret forKey:@"clientSecret"];
    }else if (btn.tag == 202){
        NSString * clientId = @"14f20bdbc7ef4fb9a84d8016845fa77b";   //趣热点-平台申请的clientId
        NSString * clientSecret = @"6bf83ad8531148609a404c0d97bfc847b09ac9f0";  //趣热点-平台申请的clientSecret
        [dict setValue:clientId forKey:@"clientId"];
        [dict setValue:clientSecret forKey:@"clientSecret"];
    }
    
    self.finishBlock(dict);
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
